package control
{
	import flash.events.Event;
	import flash.net.URLVariables;
	
	import model.ModelLocator;
	
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	import mx.rpc.remoting.RemoteObject;
	public class changeInfoCon
	{
	    internal var theModel:ModelLocator = ModelLocator.getInstance();
		private var RO;
		
		public function changeInfoCon()
		{
			RO = new RemoteObject();
			RO.destination="login";
			RO.changePwd.addEventListener(ResultEvent.RESULT,changePwdResultHandler);
			RO.changeInfo.addEventListener(ResultEvent.RESULT,ResultHandler);
			RO.addEventListener(FaultEvent.FAULT,FaultHandler);
			
		}
		
		public function doChange(formerUsername:String,username:String,sex:String,age:String,city:String,job:String,email:String,ifview:String):void{
			RO.changeInfo(formerUsername,username,sex,age,city,job,email,ifview);  
		}
		public function changePwd(username:String,password:String):void{
			RO.changePwd(username,password);
		}
		
		internal function ResultHandler(event:ResultEvent):void {
         	
         	theModel.dispatchEvent(new Event(ModelLocator.CHANGE_INFO_OK));
        }
		internal function changePwdResultHandler(event:ResultEvent):void{
			Alert.show(event.result as String);
			
		}
		internal function FaultHandler (event:FaultEvent):void {
         		Alert.show(event.fault.message,"Error")
        }

	}
}